package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.EquityPack;
import com.ktgj.customer.service.IEquityPackService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 权益包Controller
 * 
 * @author ruoyi
 * @date 2021-09-01
 */
@ControllerAdvice
@RestController
@RequestMapping("/pack")
public class EquityPackController extends BaseController
{
    @Autowired
    private IEquityPackService equityPackService;

    /**
     * 查询权益包列表
     */
    @PreAuthorize(hasPermi = "customer:pack:list")
    @GetMapping("/list")
    public TableDataInfo list(EquityPack equityPack)
    {
        startPage();
        List<EquityPack> list = equityPackService.selectEquityPackList(equityPack);
        return getDataTable(list);
    }

    /**
     * 导出权益包列表
     */
    @PreAuthorize(hasPermi = "customer:pack:export")
    @Log(title = "权益包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquityPack equityPack) throws IOException
    {
        List<EquityPack> list = equityPackService.selectEquityPackList(equityPack);
        ExcelUtil<EquityPack> util = new ExcelUtil<EquityPack>(EquityPack.class);
        util.exportExcel(response, list, "权益包数据");
    }

    /**
     * 获取权益包详细信息
     */
    @PreAuthorize(hasPermi = "customer:pack:query")
    @GetMapping(value = "/{equitypackId}")
    public AjaxResult getInfo(@PathVariable("equitypackId") Long equitypackId)
    {
        return AjaxResult.success(equityPackService.selectEquityPackById(equitypackId));
    }

    /**
     * 新增权益包
     */
    @PreAuthorize(hasPermi = "customer:pack:add")
    @Log(title = "权益包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquityPack equityPack)
    {
        return toAjax(equityPackService.insertEquityPack(equityPack));
    }

    /**
     * 修改权益包
     */
    @PreAuthorize(hasPermi = "customer:pack:edit")
    @Log(title = "权益包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquityPack equityPack)
    {
        return toAjax(equityPackService.updateEquityPack(equityPack));
    }

    /**
     * 删除权益包
     */
    @PreAuthorize(hasPermi = "customer:pack:remove")
    @Log(title = "权益包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equitypackIds}")
    public AjaxResult remove(@PathVariable Long[] equitypackIds)
    {
        return toAjax(equityPackService.deleteEquityPackByIds(equitypackIds));
    }
}
